import { http } from "@/utils/http";
import type {
  Flower,
  FlowerOptionItem,
  FlowerStatsItem,
  FlowerType,
  FlowerTypeOptionItem,
  PaginationResponse
} from "types/flower";

export const getFlowerTypePagination = (params: {
  page: number;
  page_size: number;
  kw?: string;
}) => {
  return http.request<PaginationResponse<FlowerType>>("get", "/flower/type", {
    params
  });
};

export const getFlowerTypeOptions = () => {
  return http.request<FlowerTypeOptionItem[]>("get", "/flower/type/items");
};

export const createFlowerType = (data: { name: string }) => {
  return http.request<FlowerType>("post", "/flower/type", {
    data
  });
};

export const updateFlowerType = (data: { id: number; name: string }) => {
  return http.request("put", "/flower/type", {
    data
  });
};

export const deleteFlowerType = (id: number) => {
  return http.request("delete", "/flower/type/" + id);
};

export const createFlower = (data: object) => {
  return http.request<Flower>("post", "/flower", {
    data
  });
};

export const getFlowerPagination = (params: {
  page: number;
  page_size: number;
  kw?: string;
}) => {
  return http.request<PaginationResponse<Flower>>("get", "/flower", {
    params
  });
};

export const getFlowerOptions = () => {
  return http.request<FlowerOptionItem[]>("get", "/flower/items");
};

export const getAllPresaleFlower = () => {
  return http.request<Flower[]>("get", "/flower/presale/all");
};

export const updateFlower = (data: object) => {
  return http.request("put", "/flower", {
    data
  });
};

export const deleteFlower = (id: number) => {
  return http.request("delete", "/flower/" + id);
};

export const getFlowerStats = () => {
  return http.request<FlowerStatsItem[]>("get", "/flower/stats");
};

export const updateFlowerStatus = (data: { id: number; status: number }) => {
  return http.request("patch", "/flower/status", {
    data
  });
};
